package net.wanho.shop.controller;


import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import net.wanho.shop.po.Consignee;
import net.wanho.shop.service.ConsigneeService;
import net.wanho.shop.vo.AjaxResult;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;


/**
 * <p>
 * 收货人表 前端控制器
 * </p>
 *
 * @author 猛虎王
 * @since 2024-12-24
 */
@Api(tags = "收货人表接口")
@RestController
@RequestMapping("/consignee")
@RequiredArgsConstructor
public class ConsigneeController {

    private final ConsigneeService consigneeService;

    @ApiOperation("收货人表分页查询")
    @GetMapping("/list")
    public AjaxResult findPage(@ApiParam("页码") @RequestParam(defaultValue = "1") int pagenum, @ApiParam("页大小") @RequestParam(defaultValue = "5") int pagesize, @ApiParam("查询条件") Consignee consignee) {
        PageInfo<Consignee> pageInfo = consigneeService.findPage(pagenum, pagesize, consignee);
        return AjaxResult.success(pageInfo);
    }

    @ApiOperation("根据主键查询收货人表")
    @GetMapping("/{consId}")
    public AjaxResult findById(@PathVariable Serializable consId) {
        return AjaxResult.success(consigneeService.findById(consId));
    }

    @ApiOperation("新增收货人表")
    @PostMapping
    public AjaxResult add(@RequestBody Consignee consignee) {
        consigneeService.add(consignee);
        return AjaxResult.success();
    }

    @ApiOperation("修改收货人表")
    @PutMapping
    public AjaxResult modify(@RequestBody Consignee consignee) {
        consigneeService.modify(consignee);
        return AjaxResult.success();
    }

    @ApiOperation("根据主键删除收货人表")
    @DeleteMapping("/{consId}")
    public AjaxResult removeById(@PathVariable Serializable consId) {
        consigneeService.removeById(consId);
        return AjaxResult.success();
    }

}
